home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / ARRAY.H < prev    next >
C/C++ Source or Header  |  1991-12-20  |  5KB  |  150 lines

  1. /* -*-C-*-
  2.  
  3. $Header: /scheme/users/cph/src/microcode/RCS/array.h,v 9.32 1991/12/20 22:48:56 cph Exp $
  4.  
  5. Copyright (c) 1987-91 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. #define REAL_IS_DEFINED_DOUBLE 0
  36.  
  37. #if (REAL_IS_DEFINED_DOUBLE == 0)
  38. #define REAL float
  39. #else
  40. #define REAL double
  41. #endif
  42.  
  43. #define arg_real(arg_number) ((REAL) (arg_real_number (arg_number)))
  44. #define REAL_SIZE (BYTES_TO_WORDS (sizeof (REAL)))
  45.  
  46. #define FLOAT_SIZE (BYTES_TO_WORDS (sizeof (float)))
  47. #define DOUBLE_SIZE (BYTES_TO_WORDS (sizeof (double)))
  48.  
  49. #if (REAL_IS_DEFINED_DOUBLE == 0)
  50.  
  51. /* Scheme_Arrays are implemented as NON_MARKED_VECTOR. */
  52.  
  53. #define ARRAY_P NON_MARKED_VECTOR_P
  54. #define ARRAY_LENGTH(array) ((long) (FAST_MEMORY_REF ((array), 1)))
  55. #define ARRAY_CONTENTS(array) ((REAL *) (MEMORY_LOC (array, 2)))
  56.  
  57. #else /* (REAL_IS_DEFINED_DOUBLE != 0) */
  58.  
  59. /* Scheme_Arrays are implemented as flonum vectors.
  60.    This is required to get alignment to work right on RISC machines. */
  61.  
  62. #define ARRAY_P FLONUM_P
  63. #define ARRAY_LENGTH(array) ((VECTOR_LENGTH (array)) / DOUBLE_SIZE)
  64. #define ARRAY_CONTENTS(array) ((REAL *) (MEMORY_LOC (array, 1)))
  65.  
  66. #endif /* (REAL_IS_DEFINED_DOUBLE != 0) */
  67.  
  68. extern SCHEME_OBJECT allocate_array ();
  69.  
  70. extern void C_Array_Find_Min_Max ();
  71. extern void C_Array_Complex_Multiply_Into_First_One ();
  72.  
  73. extern void C_Array_Make_Histogram ();
  74. /* REAL * Array;
  75.    REAL * Histogram;
  76.    long Length;
  77.    long npoints; */
  78.  
  79. extern void Find_Offset_Scale_For_Linear_Map();
  80. /* REAL Min;
  81.    REAL Max;
  82.    REAL New_Min;
  83.    REAL New_Max;
  84.    REAL * Offset;
  85.    REAL * Scale; */
  86.  
  87. /* The following macros implement commonly used array procs. */
  88.  
  89. /* In the following macros we assign the arguments to local variables
  90.    so as to do any computation (referencing, etc.) only once outside the loop.
  91.    Otherwise it would be done again and again inside the loop.
  92.    The names, like "MCRINDX", have been chosen to avoid shadowing the
  93.    variables that are substituted in.  WARNING: Do not use any names
  94.    starting with the prefix "mcr", when calling these macros */
  95.  
  96. #define C_Array_Scale(array, scale, n)                    \
  97. {                                    \
  98.   fast REAL * mcr_scan = (array);                    \
  99.   fast REAL * mcr_end = (mcr_scan + (n));                \
  100.   fast REAL mcrd0 = (scale);                        \
  101.   while (mcr_scan < mcr_end)                        \
  102.     (*mcr_scan++) *= mcrd0;                        \
  103. }
  104.  
  105. #define Array_Scale(array, scale)                    \
  106. {                                    \
  107.   C_Array_Scale                                \
  108.     ((ARRAY_CONTENTS (array)),                        \
  109.      (scale),                                \
  110.      (ARRAY_LENGTH (array)));                        \
  111. }
  112.  
  113. #define C_Array_Copy(from, to, n)                    \
  114. {                                    \
  115.   fast REAL * mcr_scan_source = (from);                    \
  116.   fast REAL * mcr_end_source = (mcr_scan_source + (n));            \
  117.   fast REAL * mcr_scan_target = (to);                    \
  118.   while (mcr_scan_source < mcr_end_source)                \
  119.     (*mcr_scan_target++) = (*mcr_scan_source++);            \
  120. }
  121.  
  122. #define Array_Copy(from, to)                        \
  123. {                                    \
  124.   C_Array_Copy                                \
  125.     ((ARRAY_CONTENTS (from)),                        \
  126.      (ARRAY_CONTENTS (to)),                        \
  127.      (ARRAY_LENGTH (from)));                        \
  128. }
  129.  
  130. #define C_Array_Add_Into_Second_One(from, to, n)            \
  131. {                                    \
  132.   fast REAL * mcr_scan_source = (from);                    \
  133.   fast REAL * mcr_end_source = (mcr_scan_source + (n));            \
  134.   fast REAL * mcr_scan_target = (to);                    \
  135.   while (mcr_scan_source < mcr_end_source)                \
  136.     (*mcr_scan_target++) += (*mcr_scan_source++);            \
  137. }
  138.  
  139. #define Array_Add_Into_Second_One(from,to)                \
  140. {                                    \
  141.   C_Array_Add_Into_Second_One                        \
  142.     ((ARRAY_CONTENTS (from)),                        \
  143.      (ARRAY_CONTENTS (to)),                        \
  144.      (ARRAY_LENGTH (from)));                        \
  145. }
  146.  
  147. #define mabs(x) (((x) < 0) ? (- (x)) : (x))
  148. #define max(x,y) (((x) < (y)) ? (y) : (x))
  149. #define min(x,y) (((x) < (y)) ? (x) : (y))
  150.